// auth.js
const jwt = require('jsonwebtoken');
const {secretKeys}  = require('./config');

const secretKey = secretKeys; // 用于签名和验证JWT的密钥

// 生成JWT
function generateToken(payload) {
  return jwt.sign(payload, secretKey, { expiresIn: '1h' });
}

// 验证JWT
function verifyToken(token) {
  return new Promise((resolve, reject) => {
    jwt.verify(token, secretKey, (err, decoded) => {
      if (err) {
        reject(err);
      } else {
        resolve(decoded);
      }
    });
  });
}

module.exports = {
  generateToken,
  verifyToken,
};